#ifndef UPPERCASESTREAMBUF_H_INCLUDED__
#define UPPERCASESTREAMBUF_H_INCLUDED__

#include <locale>

template <class charT, class traits = std::char_traits<charT> >
class basic_uppercase_buf : public std::basic_streambuf<charT, traits>
{
    typedef charT char_type;
    typedef typename traits::int_type int_type;
    typedef typename traits::pos_type pos_type;
    typedef typename traits::off_type off_type;
    typedef traits traits_type;
    typedef std::basic_streambuf<charT, traits> streambuf_type;

protected:
	streambuf_type* dest_;

    /** Central output function prints characters in uppercase mode. */
    virtual int_type overflow (int_type c)
	{
        if (c != EOF)
		{
            c = std::toupper(c, getloc());
			dest_->sputc(c);
        }
        return c;
    }

public:
	basic_uppercase_buf(streambuf_type* dst) : dest_(dst) {}
	~basic_uppercase_buf() { sync(); }
};

typedef basic_uppercase_buf<char> uppercase_buf;
typedef basic_uppercase_buf<wchar_t> wuppercase_buf;

#endif
